<template>
  <el-header>
    <!-- <button @click="handleCollapse">click</button> -->
    <div class="left">
      <el-icon @click="handleCollapse"><Menu /></el-icon>
      <p style="margin-left: 10px">哈皮门户网站管理系统</p>
    </div>
    <div class="right">
      <p>欢迎 {{ store.state.userInfo.userName }}</p>
      <el-dropdown :hide-on-click="false">
        <span class="el-dropdown-link">
          <el-icon :size="30" color="white"><User /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { Menu, User } from '@element-plus/icons-vue'
const store = useStore()
const router = useRouter()

// 跳转个人中心
const handleCenter = () => {
  router.push('/center')
}
// 退出
const handleLogout = () => {
  localStorage.removeItem('token')
  store.commit('clearUserInfo')
  router.push('/login')
}

const handleCollapse = () => {
  store.commit('changeCollapse')
}
</script>

<style scoped lang='scss'>
.el-header {
  background: #0F8CDC;
  color: white;
  width: 100%;
  height: 50px;
  line-height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.left, .right{
  display: flex;
  justify-content: space-between;
  align-items: center;
  i{
    cursor: pointer;
  }
}

</style>
